import "package:flutter/material.dart";
import 'package:login_demo/app_theme.dart';
import 'package:login_demo/smsCode.dart';
import 'package:login_demo/widget/TextInput.dart';
import 'package:login_demo/widget/button.dart';
import 'package:oktoast/oktoast.dart';
// desc: Register
class Register extends StatefulWidget {
  const Register({Key key}) : super(key: key);

  @override
  _RegisterState createState() => _RegisterState();
}

class _RegisterState extends State<Register> {

  TextEditingController accountController;
  TextEditingController passwordController;

  @override
  void initState() {
    accountController = new TextEditingController();
    passwordController = new TextEditingController();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.white,
        padding: EdgeInsets.only(left: 15, right: 15),
        child: Column(
          children: [
            SizedBox(height: 40),
            Row(
              children: [
                GestureDetector(
                  onTap: (){
                    Navigator.pop(context);
                  },
                  child: Icon(Icons.arrow_back_ios_rounded),
                ),
              ],
            ),
            SizedBox(height: 40),
            Text('注册', style: TextStyle(
                fontSize: 16,
                color: AppTheme.textBlack,
                fontWeight: FontWeight.bold
            )),
            SizedBox(height: 30),
            Padding(
              padding: EdgeInsets.only(left: 10, right: 10),
              child: TextInput(
                icon: Icon(Icons.phone_android_rounded),
                hintText: '请输入账号',
                textEditingController: accountController,
              ),
            ),
            SizedBox(height: 15),
            Padding(
              padding: EdgeInsets.only(left: 10, right: 10),
              child: TextInput(
                icon: Icon(Icons.lock),
                hintText: '请输入密码',
                textEditingController: passwordController,
              ),
            ),
            SizedBox(height: 80),
            Button(
              text: '下一步',
              onTap: (){
                _next();
              },
            ),
            SizedBox(height: 10),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
                  onTap: (){
                    _goBack();
                  },
                  child: Text('登录', style: TextStyle(fontSize: 14, color: AppTheme.textBlack)),
                )
              ],
            )
          ],
        ),
      ),
    );
  }

  _next(){
    if(accountController.text == ''){
      showToast('账号不可为空');
    } else if(passwordController.text == ''){
      showToast('密码不可为空');
    } else {
      Navigator.push<dynamic>(
          context,
          MaterialPageRoute(
              builder: (BuildContext context) => SmsCode()
          )
      );
    }

  }
  _goBack(){
    Navigator.pop(context);
  }
}